import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import lombok.extern.slf4j.Slf4j;
import org.example.Entity.Category;
import org.example.Entity.Dish;
import org.example.Entity.DishFlavor;
import org.example.Mapper.DishMapper;
import org.example.ReggieApplication;
import org.example.dto.DishDto;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@SpringBootTest(classes = ReggieApplication.class)
public class test {
    @Test
    public void test1() {
        log.info("(Long)null is {}",(Long)null);
        DishFlavor[] dishFlavors = {new DishFlavor(),new DishFlavor()};
        List<DishFlavor> list = Arrays.asList(dishFlavors);
        List<DishFlavor> list2 = list.stream().map(dishFlavor -> {
            dishFlavor.setDishId(1L);
            return dishFlavor;
        }).collect(Collectors.toList());
        log.info("list==list2:{}",list==list2);
    }

    @Autowired
    private DishMapper dishMapper;
    @Test
    public void test_join(){
        MPJLambdaWrapper<Dish> dishMPJLambdaWrapper = new MPJLambdaWrapper<>();
        dishMPJLambdaWrapper.selectAll(Dish.class)
                .selectAs(Category::getName,"categoryName")
                .leftJoin(Category.class,Category::getId,Dish::getCategoryId);
        IPage<DishDto> dishDtoIPage = dishMapper.selectJoinPage(new Page<>(1,10),DishDto.class,dishMPJLambdaWrapper);
    }

    @Test
    public void test_select_collection(){
        MPJLambdaWrapper<Dish> dishMPJLambdaWrapper = new MPJLambdaWrapper<>();
        dishMPJLambdaWrapper.selectAll(Dish.class)
                .selectCollection(DishFlavor.class,DishDto::getFlavors)
                .leftJoin(DishFlavor.class,DishFlavor::getDishId,Dish::getId);
        List<DishDto> dishDtos = dishMapper.selectJoinList(DishDto.class, dishMPJLambdaWrapper);
        dishDtos.forEach(dishDto -> log.info("{}",dishDto));
    }
}
